<!-- 对话框 -->
<template>
    <div class="container-dialog">
        <el-button plain @click="dialogVisible = true">
            Click to open the Dialog
        </el-button>

        <el-dialog v-model="dialogVisible" title="Tips" width="500" :before-close="handleClose" draggable>
            <span>This is a message</span>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="dialogVisible = false">Cancel</el-button>
                    <el-button type="primary" @click="dialogVisible = false">
                        Confirm
                    </el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'

const dialogVisible = ref(false)

const handleClose = (done: () => void) => {
    ElMessageBox.confirm('Are you sure to close this dialog?')
        .then(() => {
            done()
        })
        .catch(() => {
            // catch error
        })
}
</script>

<style scoped>
.container-dialog {
    padding: 20px;
}
</style>
